package com.genius.smsdao.majormanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.genius.smsbase.Domain.BaseEntity;
import com.genius.smsdao.studentmanage.domain.Grade;

import javax.persistence.*;
import java.util.List;

/**
 * @Entity:Major 专业实体类
 * 对应数据库表名：major
 * @author：
 */
@Entity
@Table(name = "major")
public class Major extends BaseEntity<Long> {

    @Column
    private String name;

    //专业到学院的多对一关系
    @JsonIgnoreProperties("majorList")
    @ManyToOne(targetEntity = Academy.class,fetch = FetchType.EAGER)
    @JoinColumn(name = "academy_id",referencedColumnName = "id")
    private Academy academy;

    //专业到年级的一对多关系
    @JsonIgnoreProperties(value = "major",allowSetters = true)
    @OneToMany(mappedBy = "major",cascade = {CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.EAGER)
    private List<Grade> gradeList;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Academy getAcademy() {
        return academy;
    }

    public void setAcademy(Academy academy) {
        this.academy = academy;
    }

    public List<Grade> getGradeList() {
        return gradeList;
    }

    public void setGradeList(List<Grade> gradeList) {
        this.gradeList = gradeList;
    }

    @Override
    public String toString() {
        return "Major{" +
                "name='" + name + '\'' +
                ", academy=" + academy +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", id=" + id +
                '}';
    }
}
